package com.ql.mangersystem.mapper;

import com.ql.mangersystem.common.Result;
import com.ql.mangersystem.entity.po.Notice;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Entity com.ql.mangersystem.entity.po.Notice
 */
@Mapper
public interface NoticeMapper {

//    @Insert("insert into `notice` (userid,time,title,content)values (#{userid},#{time},#{title},#{content})")
//    Integer save(@Param("userid") Integer userid, @Param("time") String time ,@Param("title")String title,@Param("content") String content);

    @Update("update `notice` set title = #{title},content = #{content} where id = #{id}")
    Integer update(@Param("id") Integer id, @Param("title") String title, @Param("content") String content);

    @Delete("delete from notice where id =#{id}")
    Integer delete(Integer id);

    Integer deleteBatch(List<Integer> ids);

    @Select("select * from `notice` order by id")
    List<Notice> selectAll();

    @Select("select * from `notice` where id = #{id}")
    Notice getById(Integer id);

    @Select("select count(id) from notice where title like concat('%',#{title},'%')")
    Integer count(String title);

    @Select("select n.*,u.username from notice n join user u on u.id=n.userid  where title like concat('%',#{title},'%') order by id limit #{skipNum},#{pageSize}")
    List<Notice> pageList(@Param("skipNum") Integer skipNum,@Param("pageSize") Integer pageSize, @Param("title") String title);

    @Select("select count(id) from notice")
    Integer countNum();

    @Select("select n.*,u.username from notice n join user u on u.id=n.userid order by id limit #{skipNum},#{pageSize}")
    List<Notice> page(@Param("skipNum") Integer skipNum,@Param("pageSize") Integer pageSize);

    @Update("update `notice` set open=#{open} where id = #{id}")
    Integer openChange(@Param("open") Integer open,@Param("id") Integer id);

    @Insert("insert into notice (title, content, userid, time) VALUES (#{title},#{content},#{userid},#{time})")
    int save(@Param("userid") Integer userid, @Param("time") String time, @Param("title") String title, @Param("content") String content);
}




